package ret;

import java.util.HashMap;
import java.util.Map;

public class Ret {

    public static final String OK = "ok";
    public static final String ERR = "err";
    public static final String REDIRECT = "redirect";
    public String msg;
    public String state;
    public Map<String, Object> datas = new HashMap<>();

    public static Ret ok() {
        return ok("");
    }

    public static Ret ok(String msg) {
        Ret ret = new Ret();
        ret.state = OK;
        ret.msg = msg;
        return ret;
    }

    public static Ret error(String msg) {
        Ret ret = new Ret();
        ret.state = ERR;
        ret.msg = msg;
        return ret;
    }

    public Ret data(String key, Object v) {
        datas.put(key, v);
        return this;
    }

    public static Ret redirect(String url) {
        Ret ret = new Ret();
        ret.state = REDIRECT;
        ret.msg = url;
        return ret;
    }
    public Map<String, Object> datas() {
        return datas;
    }
}
